import { updateOutWarehouseBrokeApi } from "@/api/waybillManagement/customerServiceWaybill/index";
import { message } from "ant-design-vue";

export default function OperationHook(state: any) {
  const { passData, formState, loading, formRef, emit } = state;

  const onSubmit = () => {
    formRef.value.validate().then(() => {
      loading.value = true;
      const params = {
        ...formState,
        waybillNums: passData.value.map((t: any) => t.waybillNum)
      };
      updateOutWarehouseBrokeApi(params)
        .then((res: any) => {
          const { code } = res;
          if (code === 200) {
            message.success("操作成功!");
            emit("submit");
          }
        })
        .finally(() => {
          loading.value = false;
        });
    });
  };
  const resetForm = () => {
    formRef.value.resetFields();
    emit("update:visible", false);
  };
  const changeOutWarehouseName = (e: string, option: any) => {
    formState.outWarehouseBrokerName = option.label;
  };
  return {
    resetForm,
    onSubmit,
    changeOutWarehouseName
  };
}
